/**
 * 1.属性的默认值:defaultProps
 * 2.属性的json数据
 * */
import {
  createInbizSchema,
  createDecoratorStyleSchema,
  createComponentStyleSchema,
  createMapSchema,
  createColorSchemeSchema,
  createCommonMapStyle,
  createReactiveBaseSchema,
  createBizStyleSchema,
  createControllerSchema,
} from '@inbiz/setters';
import { BiLineMap as LocaleLineMap } from './locale';

const commonProps = {
  title: {
    status: true,
    value: 'BiLineMap.title',
  },
};
export const defaultProps = {
  // labeltext: '标识',
  // colorPattern: {
  //   index: -1,
  // },
  detailView: 'none',
  colorPattern: {
    index: 0,
    colorArray: ['#1989fa', '#fbd44b', '#40c5d6', '#6befae', '#889bea', '#eaa1ff', '#a1fcff'],
  },
  mapBackground: {
    style: {
      backgroundColor: '',
      backgroundImage: '',
    },
  },
  dataLabel: ['value'],
  titlePosition: 'top',
  legendPosition: 'right',
  axis: [],
  maptitleColor: 'rgba(0,0,0, 1)',
  titleFontSize: 20,
  ifShowMapLegend: true,
  style: {
    height: '300px',
    padding: '0px 0px 0px 0px',
  },
  axises: ['horizontal', 'vertical'],
  axisesColor: '#999',
  labelColor: '#999',
  legendColor: '#999',
};

export const propsSchema = createInbizSchema({
  attribute: {
    ...createReactiveBaseSchema({
      axis: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'BiAxis',
      },
      axisSort: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'BiSort',
      },
      leftValue: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'BiValue',
        'x-component-props': {
          multiple: true,
        },
      },
      rightValue: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'BiValue',
        'x-component-props': {
          multiple: true,
        },
      },
      mapLegend: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'BiValue',
        'x-component-props': {
          unComputer: true,
        },
      },
      filter: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'BiFilter',
        'x-component-props': {
          multiple: true,
        },
      },
      detailView: {
        type: 'string',
        enum: ['none', 'skip'],
        'x-decorator': 'FormItem',
        'x-component': 'Select',
        'x-component-props': {
          defaultValue: 'none',
        },
        platform: 'web',
      },
      detailViewHref: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
        'x-reactions': {
          dependencies: ['.detailView'],
          fulfill: {
            schema: {
              'x-hidden': "{{$deps[0] == 'none'}}",
            },
          },
        },
      },
      xaxisTitle: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
        platform: 'web',
      },
      xaxisUnit: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
        platform: 'web',
      },
      yxisTitleLeft: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
        platform: 'web',
      },
      yxisUnitLeft: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
        platform: 'web',
      },
      yxisTitleRight: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
        platform: 'web',
      },
      yxisUnitRight: {
        type: 'string',
        'x-decorator': 'FormItem',
        'x-component': 'Input',
        platform: 'web',
      },
    }),
  },
  style: {
    ...createComponentStyleSchema({
      ...createCommonMapStyle({ hasRatio: false }),
      ...createBizStyleSchema(undefined, {}, undefined, undefined, false),
    }),
    ...createDecoratorStyleSchema(),
    ...createColorSchemeSchema(),
  },
  senior: {
    ...createMapSchema(),
  },
  controller:createControllerSchema({
    events: [{
      name:'onClick',
      label:'点击获取每项数据',
      platform:'web'
    },
    {
      name:'onParams',
      label:'请求前修改请求参数',
      platform:'web',
      isConfigEvent:true
    },
    {
      name:'onRequest',
      label:'自定义请求',
      platform:'web',
      isConfigEvent:true
    },
    {
      name:'onData',
      label:'格式化数据',
      platform:'web',
      isConfigEvent:true
    }
  ]
  })
});

export const defaultBehavior = {
  name: 'BiLineMap',
  selector: (node) => node.props['x-component'] === 'BiLineMap',
  extends: ['Field'],
  designerLocales: LocaleLineMap,
  designerProps: { propsSchema },
};

export const defaultResource = {
  icon: 'Line',
  elements: [
    {
      componentName: 'Field',
      props: {
        ...commonProps,
        type: 'string',
        'x-decorator': 'Container',
        'x-component': 'BiLineMap',
        'x-component-props': defaultProps,
      },
    },
  ],
};
